<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<?php
ob_start();
session_start();
if (empty($_SESSION["loginusername"])) {
    Header("Location: firstphp.php");
}
if (!empty($_SESSION["userType"])) {
    $userType = $_SESSION["userType"];
}
?>
<html>
    <head>
        <meta name="description" content="" />
        <link rel="stylesheet" type="text/css" href="http://localhost/Eldercare/jquery/easyui.css">
        <link rel="stylesheet" type="text/css" href="http://localhost/Eldercare/jquery/icon.css">
        <script type="text/javascript" src="http://localhost/Eldercare/jquery/jquery-1.6.min.js"></script>
        <script type="text/javascript" src="http://localhost/Eldercare/jquery/jquery-1.4.4.min.js"></script>

        <script type="text/javascript" src="http://localhost/Eldercare/jquery/jquery.easyui.min.js"></script>
        <style type="text/css">
            #fm{
                margin:0;
                padding:10px 30px;
            }
            .ftitle{
                font-size:14px;
                font-weight:bold;
                color:#666;
                padding:5px 0;
                margin-bottom:10px;
                border-bottom:1px solid #ccc;
            }
            .fitem{
                margin-bottom:5px;
            }
            .fitem label{
                display:inline-block;
                width:80px;
            }
        </style>
        <link href="http://localhost/Eldercare/finalstyle.css" rel="stylesheet" type="text/css" media="all" />	
    </head>
    <style type="text/css">
        body {
            background: #FFFFFF url("images/bg.png") repeat;
            background-attachment:fixed;
        }
        .button 
        {
            background-color:beige;
            cursor:pointer; }

        .btn
        {
            background-color:#FFF5EE;
            cursor:pointer;
        }
        }
    </style>
    <body>
        <div class="banner"></div>
        <div id="main">
            <div class="left-wrapper">
                <div class="logo">
                </div>
                <div class="menu-wrapper">
                    <div id='cssmenu' >     
                        <ul>



                            <?php
                            if ($userType == "Therapy Assistant") {
                                //if TA
                                echo "<li class='has-sub' class='active'><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance Taking</span></a></li>
			 <li class='last'><a href='http://localhost/Eldercare/ViewAttendanceRecord.php'><span>View Attendance</span></a></li>
			 </ul>
			  </li>
			  <li class='has-sub'><a href='#'><span>Profile</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Client.php'><span>Client</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='http://localhost/Eldercare/ActRecords.php'><span>Activities</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ActRecords.php'><span>Activity Recording</span></a></li>
		 <li class='last'><a href='http://localhost/Eldercare/ViewActRecord.php'><span>View Activity Records</span></a></li>
      </ul>
   </li>
   <li><a href='http://localhost/Eldercare/Reports.php'><span>Reports</span></a></li>
   <li><a href='http://localhost/Eldercare/ManagePassword.php'><span>Change Passwords</span></a></li>
     
			 ";
                            } else if ($userType == "Centre Manager") {
                                echo "
			<li class='has-sub' class='active'><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance Taking</span></a></li>
			 <li><a href='http://localhost/Eldercare/ViewAttendanceRecord.php'><span>View Attendance</span></a></li>
			<li><a href='http://localhost/Eldercare/BackDate.php'><span>BackDate</span></a></li>
			<li class='last'><a href='http://localhost/Eldercare/VerifyAttendance.php'><span>Verify Attendance</span></a></li>
			</ul>
			<li class='has-sub'><a href='#'><span>Profile</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Client.php'><span>Client</span></a></li>
         <li><a href='http://localhost/Eldercare/User.php'><span>User</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='http://localhost/Eldercare/ActRecords.php'><span>Activities</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ActRecords.php'><span>Activity Recording</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ViewActRecord.php'><span>View Activity Records</span></a></li>
      </ul>
   </li>
   <li><a href='http://localhost/Eldercare/Reports.php'><span>Reports</span></a></li>
    <li class='has-sub'><a href='#'><span>Password</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ManagePassword.php'><span>Change Passwords</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ForgetPasswords.php'><span>Forget Password</span></a></li>
      </ul>
   </li>
			";
                            } else {
                                echo "
	<li class='has-sub' class='active'><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance Taking</span></a></li>
			 <li><a href='http://localhost/Eldercare/ViewAttendanceRecord.php'><span>View Attendance</span></a></li>
			<li><a href='http://localhost/Eldercare/BackDate.php'><span>BackDate</span></a></li>
			<li class='last'><a href='http://localhost/Eldercare/VerifyAttendance.php'><span>Verify Attendance</span></a></li>
			</ul>
			<li class='has-sub'><a href='#'><span>Profile</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Client.php'><span>Client</span></a></li>
         <li><a href='http://localhost/Eldercare/User.php'><span>User</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/Centres.php'><span>Centres</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='http://localhost/Eldercare/ActRecords.php'><span>Activities</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Activities.php'><span>Manage Current Activities</span></a></li>
         <li><a href='http://localhost/Eldercare/ActRecords.php'><span>Activity Recording</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ViewActRecord.php'><span>View Activity Records</span></a></li>
      </ul>
   </li>
   <li><a href='http://localhost/Eldercare/Holidays.php'><span>Holiday</span></a></li>
   <li><a href='http://localhost/Eldercare/Reports.php'><span>Reports</span></a></li>
    <li class='has-sub'><a href='#'><span>Password</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ManagePassword.php'><span>Change Passwords</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ForgetPasswords.php'><span>Forget Password</span></a></li>
      </ul>
   </li>
			";
                            }
                            ?>

                        </ul>
                        </li>



                        </ul>
                    </div>
                    <div class="clear"></div></div></div>
            <div class="content">
                <div class="content2">
                    <b style="float:right; margin: 0px 0 0 0">  
                        <?php
//session_start();
                        if (!empty($_SESSION["centreName"])) {
                            $Username = $_SESSION["loginusername"];
                            $centreName = $_SESSION["centreName"];
                            echo "Welcome, " . $Username . " ! <br>" . $centreName . " Branch";
                        } else {
                            $Username = $_SESSION["loginusername"];
                            echo "Welcome, " . $Username;
                        }
                        ?>

                        <?php
                        ?>
                        <?php
//session_start();
// set timeout period in seconds
                        $inactive = 7200;
// check to see if $_SESSION['timeout'] is set
                        if (isset($_SESSION["timeout"])) {
                            $session_life = time() - $_SESSION["timeout"];
                            if ($session_life > $inactive) {
                                session_destroy();
                                Header("Location: Timeout.php");
                            }
                        }
                        $_SESSION["timeout"] = time();
                        ?>

                        <input type="submit" class="button" value="Logout" onclick="parent.location = 'logout.php'"></b>
                    <div class="clear"></div>


                    <div id="wrap-content" style="margin:0px auto 0px auto; padding: 10px">
                        <form action="Getpassword.php" method="post" name="formLogin" style="margin:0px auto 0px auto;">

                            <?php
                            if (empty($_POST["Username"])) {
                                Header("Location:forgetpassword.php");
                            }
                            if($_SESSION["loginusername"]==$_POST["Username"]){
                                echo "<p align='center'> <font color=red>You cannot reset your own password!</p>";
                                            echo "<form method='post'>";
                                            echo "<p align='center'> <input type='submit' name='btnBack' id='btnBack' class='btn' value='Back'/></form></p>";
                            }
                            else
                            {
                            if ($userType == "Centre Manager") {
                                if (!empty($_POST["Username"])) {
                                    $checkanswer = $_POST["Username"];
                                    include 'conn.php';

                                    $retrieve = "Select * from user where Username= '$checkanswer'";
                                    $sql = "Select * from user where Username= '$checkanswer'";
                                    $result = @mysql_query($sql);
                                    $username = mysql_query($retrieve);
                                    $row = mysql_fetch_array($username);
                                    if ($row["Username"] == $checkanswer) {
                                        //if($row["UserType"]=="Therapy Assistant") {
                                        //echo'<script type="text/javascript">alert("Please look for your Centre Manager!")</script>';

                                        if ($row["UserType"] == "Therapy Assistant") {
                                            $pass = rand();
                                            $passHashed = md5($pass);
                                            $pass = substr($pass, 0, 7);

                                            $query = mysql_query("UPDATE user SET Password = '$passHashed' WHERE Username='$checkanswer'");
                                            if ($query) {
                                                echo "<b><p align = 'center'>Your new password is: </b>" . $pass;
                                                //echo "<p align = 'center'><a href='Firstphp.php'><br> Back to Login.</a>";
                                                $_SESSION["Username"] = 0;
                                            } else {
                                                echo 'Please try again';
                                                $_SESSION["Username"] = 0;
                                            }
                                        } else {
                                            echo "<p align='center'> <font color=red> You can only change Therapy Assistants Password!</p>";
                                            echo "<form method='post'>";
                                            echo "<p align='center'> <input type='submit' name='btnBack' id='btnBack' class='btn' value='Back'/></form></p>";
                                        }
                                    } else {

                                        echo "<p align='center'> <font color=red> You've entered the wrong Username, please check again!</p>";
                                        echo "<form method='post'>";
                                            echo "<p align='center'> <input type='submit' name='btnBack' id='btnBack' class='btn' value='Back'/></form></p>";
                                        //echo "<p align = 'center'><a href='Forgetpassword.php'><br> Please click here to enter again.</a>";
                                    }
                                }
                            } else if ($userType == "System Admin") {
                                if (!empty($_POST["Username"])) {
                                    $checkanswer = $_POST["Username"];
                                    include 'conn.php';
                                    $retrieve = "Select * from user where Username= '$checkanswer'";
                                    $sql = "Select * from user where Username= '$checkanswer'";
                                    $result = @mysql_query($sql);
                                    $username = mysql_query($retrieve);
                                    $row = mysql_fetch_array($username);
                                    if ($row["Username"] == $checkanswer) {
                                        //if($row["UserType"]=="Therapy Assistant") {
                                        //echo'<script type="text/javascript">alert("Please look for your Centre Manager!")</script>';

                                        
                                            $pass = rand();
                                            $passHashed = md5($pass);
                                            $pass = substr($pass, 0, 7);

                                            $query = mysql_query("UPDATE user SET Password = '$passHashed' WHERE Username='$checkanswer'");
                                            if ($query) {
                                                echo "<b><p align = 'center'>Your new password is: </b>" . $pass;
                                                //echo "<p align = 'center'><a href='Firstphp.php'><br> Back to Login.</a>";
                                                $_SESSION["Username"] = 0;
                                            } else {
                                                echo 'Please try again';
                                                $_SESSION["Username"] = 0;
                                            }
                                        
                                    } else {

                                        echo "<p align='center'> <font color=red> You've entered the wrong Username, please check again!</p>";
                                        echo "<form method='post'>";
                                            echo "<p align='center'> <input type='submit' name='btnBack' id='btnBack' class='btn' value='Back'/></form></p>";
                                        //echo "<p align = 'center'><a href='Forgetpassword.php'><br> Please click here to enter again.</a>";
                                    }
                                }
                            }
                            }
                            if(isset($_POST['btnBack']))
                            {
                                header('Location: ForgetPasswords.php');
                            }
                            ?>
                        </form>
                    </div><div class="clear"></div></div>
            </div>
    </body> </div>
</html>